<#
会话恢复能力检查（原生 PowerShell）
用途：检查是否存在 config/rules.env 的 INIT_TIMESTAMP 以及 docs/ai_initialization_guide.md。
用法：
  pwsh -File scripts/windows/check-session-recovery.ps1
#>
param()

$WindowsDir = Split-Path -Parent $PSCommandPath
$ScriptsDir = Split-Path -Parent $WindowsDir
$RepoDir = Split-Path -Parent $ScriptsDir

$envFile = Join-Path $RepoDir 'config/rules.env'
if (!(Test-Path $envFile)) { $envFile = Join-Path $RepoDir 'config/rules.env' }
$guide = Join-Path $RepoDir 'docs/ai_initialization_guide.md'
if (!(Test-Path $guide)) { $guide = Join-Path $RepoDir 'docs/ai_initialization_guide.md' }

$ok = $true
if (!(Test-Path $envFile)) { Write-Warning "缺少配置文件：$envFile"; $ok = $false }
else {
  $raw = Get-Content -Raw $envFile
  if ($raw -notmatch '(?m)^INIT_TIMESTAMP=') { Write-Warning "rules.env 缺少 INIT_TIMESTAMP"; $ok = $false }
}
if (!(Test-Path $guide)) { Write-Warning "缺少初始化指南：$guide"; $ok = $false }

if ($ok) { Write-Host "会话恢复能力检查通过"; exit 0 } else { exit 2 }
